import javax.swing.*;
import java.awt.*;

public class DrawPanel_new extends JPanel {

	private static final long serialVersionUID = 1L;
	private Shapes[] shapes;
	public DrawPanel_new(){
		setBackground(Color.BLACK);
	}
	public DrawPanel_new(Shapes[] shapes){
		if(shapes==null){			//查一下是不是全为空
			System.out.println("错误，尝试识别空的数组");
		}
		else {
			this.shapes = shapes;
		}
	}
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		if(shapes==null){
			System.out.println("错误，尝试识别空的数组");
			return;
		}
		for(Shapes shapes1:shapes){
			try {
				shapes1.draw(g);
			}catch (ClassCastException e){
				System.out.println("数组中疑似有非图形输入或该图形未被正确归类");
			}catch (NullPointerException e){
				System.out.println("错误，数组中出现null，请调整输入");
			}
		}
	}
}//这样更改的话，只需让新的图形实现Shapes即可
